package br.com.sovi.gwt.client.application;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Application {

	private static Application instance;

	public static Application get() {
		if (instance == null) {
			instance = new Application();
		}
		return instance;
	}

	private Map<String, Object> attributes = new HashMap<String, Object>();

	private List<AttributeListener> attributeListeners = new ArrayList<AttributeListener>();

	public void addAttribute(String key, Object value) {
		attributes.put(key, value);

		for (AttributeListener l : attributeListeners) {
			l.attributeAdded(key, value);
		}
	}

	public void removeAttribute(String key) {
		attributes.remove(key);

		for (AttributeListener l : attributeListeners) {
			l.attributeRemoved(key);
		}
	}

	public void addAttributeListener(AttributeListener attributeListener) {
		attributeListeners.add(attributeListener);
	}

	public void removeAttributeListener(AttributeListener attributeListener) {
		attributeListeners.remove(attributeListener);
	}

	public Object getAttribute(String usuarioLogadoAttr) {
		return attributes.get(usuarioLogadoAttr);
	}

}
